import { DailyInfo } from "../model/DailyInfo";
import { StringHelper } from "../../../com/gengine/utils/StringHelper";
import { ConfigManager } from "../../../com/gengine/resource/ConfigManager";
type int = number;
//class DailyItemConfig
    
    export  class DailyItemConfig
    {
        constructor()
        {
            
            this._map = new Map<any, any> /* flash.utils.Dictionary */();
            if (DailyItemConfig._instance != null) 
            {
                throw new Error(" DailyItemConfig 单例 ");
            }
            this.init();
            return;
        }

        /* internal  */write(arg1: Object): void
        {
            var loc1=null;
            var loc2=null;
            var loc3=0;
            var loc4=arg1;
            for(loc2 of loc4) 
            {
                loc1 = new DailyInfo();
                loc1.type = loc2.id;
                loc1.name = StringHelper.getString(loc2.name);
                loc1.des = StringHelper.getString(loc2.des);
                loc1.url = StringHelper.getString(loc2.url);
                loc1.levelListStr = StringHelper.getString(loc2.levelList);
                loc1.level = loc2.level;
                loc1.levelWorld = loc2.levelworld;
                loc1.time = loc2.time;
                loc1.copyId = loc2.copyid;
                loc1.button = loc2.button;
                loc1.subtype = StringHelper.getString(loc2.subtype);
                loc1.subName = StringHelper.getString(loc2.subname);
                loc1.setActType(loc2.type);
                loc1.recommend = loc2.recommend;
                loc1.countTotal = loc2.maxcount;
                loc1.processValue = loc2.processValue;
                loc1.bossImg = StringHelper.getString(loc2.bossimg);
                loc1.rewardDes = StringHelper.getString(loc2.rewardDes);
                loc1.bossAdd = StringHelper.getString(loc2.bossAdd);
                loc1.upateItem(StringHelper.getString(loc2.item));
                loc1.upateAward(StringHelper.getString(loc2.reward));
                loc1.updateDayOfWeek(StringHelper.getString(loc2.dayOfWeek));
                loc1.updateStartDtAndEndDt(StringHelper.getString(loc2.startDt), StringHelper.getString(loc2.endDt));
                loc1.pvpEffect = loc2.pvpEffect;
                loc1.updateWeekType(loc2.weekType);
                this._map[loc1.type] = loc1;
            }
            return;
        }

        public init(): void
        {
            var loc1=ConfigManager.instance.getJSONByFileName("t_daily_reward.json");
            this.write(loc1);
            return;
        }

        public getInfoByType(arg1: int): DailyInfo
        {
            return this._map[arg1];
        }

        public getDailyArrayByWalkthroughType(arg1: int, arg2: int): Array<any>
        {
            var loc2=null;
            var loc1=[];
            var loc3=0;
            var loc4=this._map;
            for(loc2 of loc4) 
            {
                if (loc2.subtype.toString().substring(0, 1) != arg1.toString()) 
                {
                    continue;
                }
                if (!(loc2.level <= arg2)) 
                {
                    continue;
                }
                loc1.push(loc2);
            }
            return loc1;
        }

        public getDailyArrayByWalkthroughSubType(arg1: int, arg2: int, arg3: Boolean=true): Array<any>
        {
            var loc3=null;
            var loc4=null;
            var loc7=0;
            var loc1=[];
            var loc2=[];
            var loc8=0;
            var loc9=this._map;
            for(loc3 of loc9) 
            {
                if (!(!(loc3.subtype.indexOf(arg1.toString()) == -1) && loc3.level <= arg2 && loc3.isActive())) 
                {
                    continue;
                }
                loc7 = loc3.getRecommentByType(arg1);
                loc3.wtRecommend = loc7;
                if (arg3) 
                {
                    loc2.push({"recomment": loc7, "daily": loc3});
                    continue;
                }
                loc2.push(loc3);
            }
            if (arg3) 
            {
                loc2.sortOn("recomment", Array.DESCENDING | Array.NUMERIC);
            }
            var loc5=loc2.length >= 3 ? 3 : loc2.length;
            var loc6=0;
            while (loc6 < loc5) 
            {
                loc4 = loc2[loc6];
                if (arg3) 
                {
                    loc1.push(loc4.daily);
                }
                else 
                {
                    loc1.push(loc4);
                }
                ++loc6;
            }
            return loc1;
        }

        public static get instance(): DailyItemConfig
        {
            if (DailyItemConfig._instance == null) 
            {
                DailyItemConfig._instance = new DailyItemConfig();
            }
            return DailyItemConfig._instance;
        }

        /* internal */ /* var */_map: Map<any, any> /* flash.utils.Dictionary */;

        /* internal */ static /* var */_instance: DailyItemConfig;
    }
